package org.mspring.mlog.web.module.web.widget;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mspring.mlog.entity.security.User;
import org.mspring.mlog.service.security.UserService;
import org.mspring.platform.utils.RequestUtils;
import org.mspring.platform.web.freemarker.widget.stereotype.Widget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 
 * @author Gao Youbo
 * @since 2013年7月17日
 */
@Widget
@RequestMapping("/widget/user")
public class Widget_UserWidget extends Widget_AbstractWidget {
    @Autowired
    private UserService userService;

    @RequestMapping("/newRegister")
    public String newRegister(@RequestParam(required = false, defaultValue = "/widget/user/newRegister") String tpl, HttpServletRequest request, HttpServletResponse response, Model model) {
        Integer num = RequestUtils.getRequestParameterAsInteger(request, "num");
        if (num == null) {
            num = 10;
        }
        List<User> users = userService.getNewRegister(num);
        model.addAttribute("users", users);
        return "skin:" + tpl;
    }
}
